package org.csu.jpetstore_users_backend_pj.util;
import okhttp3.FormBody;
import okhttp3.Request;
import org.springframework.stereotype.Component;

@Component
public class RequestFactory {

    public Request createTokenRequest(String code, String clientId, String clientSecret, String redirectUri) {
        FormBody body = new FormBody.Builder()
                .add("grant_type", "authorization_code")
                .add("code", code)
                .add("client_id", clientId)
                .add("redirect_uri", redirectUri)
                .add("client_secret", clientSecret)
                .build();

        return new Request.Builder()
                .url("https://gitee.com/oauth/token")
                .post(body)
                .build();
    }

    public Request createUserRequest(String accessToken) {
        return new Request.Builder()
                .url("https://gitee.com/api/v5/user?access_token=" + accessToken)
                .build();
    }
}